//
//  SegmentBtn.m
//  mmbang
//
//  Created by lihuaming on 14-10-24.
//  Copyright (c) 2014年 iyaya. All rights reserved.
//

#import "SegmentBtn.h"

@implementation SegmentBtn

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        _imageSize = CGSizeZero;
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    if (!CGSizeEqualToSize(CGSizeZero, _imageSize)) {
        self.imageView.size = _imageSize;
    }
    
    CGSize titleLabelSizeFit = [self.titleLabel sizeThatFits:CGSizeMake(CGRectGetWidth(self.bounds), self.titleLabel.height)];
    self.titleLabel.width = titleLabelSizeFit.width;
    
    self.titleLabel.centerX = CGRectGetMidX(self.bounds);
    self.imageView.centerX = CGRectGetMidX(self.bounds);
    self.imageView.top = (CGRectGetHeight(self.frame) - (CGRectGetHeight(self.titleLabel.frame)+CGRectGetHeight(self.imageView.frame)))/2.0;
    self.titleLabel.top = (CGRectGetHeight(self.frame) - (CGRectGetHeight(self.titleLabel.frame)+CGRectGetHeight(self.imageView.frame)))/2.0 +CGRectGetHeight(self.imageView.frame)+[_verSpace floatValue];
    self.titleLabel.frame = CGRectMake(ceilf(self.titleLabel.left), ceilf(self.titleLabel.top), ceilf(self.titleLabel.width), ceilf(self.titleLabel.height));
    self.imageView.frame = CGRectMake(ceilf(self.imageView.left), ceilf(self.imageView.top), ceilf(self.imageView.width), ceilf(self.imageView.height));
    
}
-(void)setVerSpace:(NSNumber*)verSpace
{
    _verSpace = verSpace;
    [self layoutSubviews];
}
@end
